Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more unit test to cover code_pkcs11.c #195

Merged
merged 4 commits into from
May 16, 2024

Conversation

chinglee-iot
Copy link
Member

Description

Add more unit test to cover code_pkcs11.c
In this PR:

  • Code coverage for core_pkcs11.c is now 100%
  • Remove local function prvOpenSession since it is only used in xInitializePkcs11Session and pxFunctionList is already obtained in this function.
  • Remove redundant functional pointer check in xInitializePkcs11Token.
  • Add more C_GetFunctionList check

Test Steps

N/A

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@chinglee-iot chinglee-iot force-pushed the update-core-pkcs11-unit-test branch from 5c7bdfa to da9e3a8 Compare May 16, 2024 04:26
}

if( xResult == CKR_OK )
{
xResult = xInitializePKCS11();
}
xResult = C_GetFunctionList( &pxFunctionList );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move C_GetFunctionList call here for CBMC check.

@@ -295,19 +275,30 @@ CK_RV xInitializePkcs11Session( CK_SESSION_HANDLE * pxSession )
}

/* Open a PKCS #11 session. */
if( ( xResult == CKR_OK ) && ( pxSlotId != NULL ) && ( xSlotCount >= 1UL ) )
if( ( xResult == CKR_OK ) && ( xSlotCount >= 1UL ) )
Copy link
Member Author

@chinglee-iot chinglee-iot May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( pxSlotId != NULL ) is a redundant check since the value xResult ensure this won't be NULL.

{
/* We will take the first slot available.
* If your application has multiple slots, insert logic
* for selecting an appropriate slot here.
*/
xResult = prvOpenSession( pxSession, pxSlotId[ 0 ] );
if( pxFunctionList->C_OpenSession != NULL )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwind prvOpenSession here to reuse the pxFunctionList


if( ulCalls == 3 )
{
xResult = CKR_OK;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment is not needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will cover this in PR #196

@chinglee-iot chinglee-iot merged commit a0170b8 into FreeRTOS:main May 16, 2024
12 checks passed
@chinglee-iot chinglee-iot deleted the update-core-pkcs11-unit-test branch May 16, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants